home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / mis_cnvt / crea_db / create11.bas < prev    next >
Encoding:
BASIC Source File  |  1987-12-21  |  3.4 KB  |  140 lines

  1. ON ERROR GOTO TRAP
  2. '
  3. ' Prog Name  = CREATE.BAS
  4. ' Run String = CREATE <filename>
  5. ' Author     = Douglas Welch
  6.   Version$    = "1.1"
  7. ' Date = December 16, 1987
  8. '
  9. ' Run Name    Date  Who Ver#  Description/Mod's
  10. ' ---------- ------ --- ----  ----------------------------------
  11. ' CREATE     871221 DEW  1.0  Create DBF Files directly
  12. ' CREATE     871221 DEW  1.1  Add support for MEMO Fields and Files
  13. '
  14. ' Create DBASE III+ / Foxbase+ (tm) DBF files directly
  15. '
  16. ' -- Variables --
  17. '
  18. ' INFILE$       -  Name of Input File
  19. ' COMMAND$      -  Command Line Arguments
  20. ' DBFNAME$      -  Name of DBF to be created
  21. ' MEMO$         -  Are there any memo fields (Y/N)
  22. ' SIZE$         -  Total of Field Characters
  23. ' NUMFLD$       -  Number of Fields
  24. ' DATE$         -  Current Date
  25. ' FDNAME$()     -  FIELDNAME
  26. ' TYPE$()       -  FIELD TYPE
  27. ' WID()         -  FIELD WIDTH
  28. ' DEC()         -  DECIMAL NUMBER
  29. '
  30. ' --- Data File Structure ---
  31. '
  32. ' Name of Database to be created
  33. ' MEMO Fields (Y/N)
  34. ' Total Character Count of DBF File
  35. ' Number of Fields in DBF File
  36. ' Field Name, Field Type, Field Width, Decimal Number
  37. ' etc...
  38. '========================================================
  39. '
  40. ' Dimesion the arrays to hold field data
  41. DIM FDNAME$(30), TYPE$(30)
  42. DIM WID%(30), DEC%(30)
  43.  
  44. ' Clear the screen
  45. CLS
  46. ' Header
  47. PRINT "dBase DBF File Creation Utility Version "+ VERSION$
  48. PRINT "(C) Douglas E. Welch 1987"
  49. PRINT "-----------------------------------"
  50. PRINT
  51.  
  52. ' If ARG is given then do not prompt
  53. IF COMMAND$ = "" THEN
  54.    LINE INPUT "Input file  : ", INFILE$
  55.    IF INFILE$  = "" THEN GOTO QUIT
  56. ELSE
  57.    INFILE$ = COMMAND$
  58. END IF
  59.  
  60. ' Open Files
  61. OPEN INFILE$ FOR INPUT AS #1
  62.  
  63. ' Read in the file until file is empty
  64. DO WHILE NOT EOF(1)
  65.    ' Get Header Information
  66.    LINE INPUT #1, DBFNAME$
  67.    LINE INPUT #1, MEMO$
  68.    LINE INPUT #1, SIZE$
  69.    LINE INPUT #1, NUMFLD$
  70.    ' Read in Field info
  71.    FOR COUNT% = 1 TO VAL(NUMFLD$)
  72.       INPUT#1,FDNAME$(COUNT%),TYPE$(COUNT%),WID%(COUNT%),DEC%(COUNT%)
  73. ' Pad Out Field Name with nulls
  74.       SHORT = 11 - LEN(FDNAME$(COUNT%))
  75.       FDNAME$(COUNT%) = FDNAME$(COUNT%) + STRING$(SHORT,CHR$(0))
  76. ' Debug
  77. ' PRINT FDNAME$(COUNT%),TYPE$(COUNT%),WID%(COUNT%),DEC%(COUNT%)
  78.    NEXT COUNT%
  79.  
  80. ' Do some data type conversion
  81. SIZE = VAL(SIZE$)
  82. YY = VAL(MID$(DATE$,9,2))
  83. DD = VAL(MID$(DATE$,4,2))
  84. MM = VAL(MID$(DATE$,1,2))
  85.  
  86. PRINT
  87. PRINT "Creating "; DBFNAME$ ; " as dBase III+ file...";
  88.  
  89. ' If there is a memo field then create the memo file
  90. IF MEMO$ = "Y" THEN
  91.    TEMP$ = LEFT$(DBFNAME$,LEN(DBFNAME$)-3)
  92.    OPEN TEMP$+"DBT" FOR BINARY AS #3
  93.    CLOSE #3
  94. END IF
  95.  
  96. ' Open output file
  97. OPEN DBFNAME$ FOR BINARY AS #2
  98.  
  99. ' Insert header in the file
  100. IF MEMO$ = "Y" THEN
  101.    PUT$ #2, CHR$(131)
  102. ELSE
  103.    PUT$ #2, CHR$(3)
  104.  
  105. END IF
  106.  
  107. PUT$ #2, CHR$(YY)+CHR$(MM)+CHR$(DD)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)
  108. PUT$ #2, CHR$(193)+CHR$(0)+CHR$(SIZE)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)
  109.  
  110. ' Insert 16 bytes of nulls
  111. FOR I = 1 TO 16:PUT$ #2, CHR$(0):NEXT I
  112.  
  113. ' Insert Fields into output field
  114. FOR I = 1 TO VAL(NUMFLD$)
  115. PUT$ #2,FDNAME$(I)+TYPE$(I)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)
  116. PUT$ #2,CHR$(WID%(I))+CHR$(DEC%(I))
  117.    FOR J = 1 TO 14
  118.       PUT$ #2, CHR$(0)
  119.    NEXT J
  120. NEXT I
  121.  
  122. ' Insert End of Dbase info marker
  123. PUT$ #2, CHR$(13)
  124. PRINT "Done"
  125. ' Close the output files
  126. CLOSE #2
  127. WEND
  128.  
  129. QUIT:
  130. CLOSE #1
  131. CLOSE #2
  132. PRINT
  133. PRINT "Done..."
  134. END
  135.  
  136. TRAP:
  137. IF ERR = 53 THEN PRINT:PRINT "File not Found: "+INFILE$ : BEEP
  138. GOTO QUIT
  139. END
  140.